﻿#include "syscpumonitor.h"
#include "systemmonitormanager.h"
#include "syscfg.h"
#include "common.h"

SysCPUMonitor::SysCPUMonitor(SystemMonitorManager * manager):manager(manager)
{

}

int SysCPUMonitor::start()
{
    bool isFirstTime = true;

    while(state == RunableStateStarted)
    {
        double usage = CpuUseage();
        manager->updateCurrentCpuUsage(usage);

        int interval = CPU_CHECK_INTERVAL_SECONDS;

        for(int i = 0; i < interval*5; i ++)
        {

            if(state == RunableStateStarted)
            {
                Sleep(200);
                if(isFirstTime)
                {
                    isFirstTime = false;
                    break;
                }
            }
            else
            {
                break;
            }
        }
    }

    return f_success;
}
